package com.project.controller;

import com.project.bean.ProductBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("product")
public class ProductController {
    private static List<ProductBean> productList = new ArrayList<>();
    static{
        productList.add(new ProductBean(1,"荣耀Play5T Pro 6400万双摄","http://localhost:8080/productImage/1.jpg",1099,999));
        productList.add(new ProductBean(2,"三星 SAMSUNG Galaxy S22","http://localhost:8080/productImage/2.jpg",1599,1299));
        productList.add(new ProductBean(3,"Apple iPhone 13 (A2634)","http://localhost:8080/productImage/3.jpg",2300,2188));
        productList.add(new ProductBean(4,"vivo iQOO Neo5","http://localhost:8080/productImage/4.jpg",800,739));
        productList.add(new ProductBean(5,"荣耀60 前后双曲设计","http://localhost:8080/productImage/5.jpg",1800,1600));
        productList.add(new ProductBean(6,"OPPO K9x 8+128GB","http://localhost:8080/productImage/6.jpg",1566,1499));
        productList.add(new ProductBean(7,"华为HMS系统超薄智能手机","http://localhost:8080/productImage/7.jpg",2500,2488));
        productList.add(new ProductBean(8,"荣耀畅玩20 5000mAh","http://localhost:8080/productImage/8.jpg",600,488));
        productList.add(new ProductBean(9,"酷睿i7+独显","http://localhost:8080/productImage/9.jpg",4588,4399));
        productList.add(new ProductBean(10,"华为笔记本电脑MateBook","http://localhost:8080/productImage/10.jpg",3600,3488));
        productList.add(new ProductBean(11,"戴尔DELL成就3400","http://localhost:8080/productImage/11.jpg",5800,5750));
        productList.add(new ProductBean(12,"荣耀笔记本MagicBook","http://localhost:8080/productImage/12.jpg",6800,6500));
        productList.add(new ProductBean(13,"惠普(HP)战66五代","http://localhost:8080/productImage/13.jpg",4200,3999));
        productList.add(new ProductBean(14,"联想笔记本电脑小新Pro16","http://localhost:8080/productImage/14.jpg",7200,7155));
    }

    @RequestMapping("findProduct")
    public List<ProductBean> findProduct(int pageNO){
        int size = pageNO*6>productList.size()?productList.size():pageNO*6;
        List<ProductBean> list = new ArrayList<>();
        for(int i=(pageNO-1)*6;i<size;i++){
            list.add(productList.get(i));
        }
        return list;
    }
}
